﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Security.Cryptography;
using System.Text;
using System.Web.UI.WebControls;
using Common;
using Kronos.DatabaseModels;

namespace Kronos.Classes
{
    public class BaseUserModel
    {

        protected soen341dBEntities soen341dB_context;
        protected  Users newUser;
        protected virtual string UserLoggedIn { get; set; }
        protected  string UserIn;
        protected  Label Notification;
        protected virtual string EncryptPwd(string originalPwd)
        {    
            MD5 crypto_Service = new MD5CryptoServiceProvider();
            return BitConverter.ToString(crypto_Service.ComputeHash(ASCIIEncoding.Default.GetBytes(originalPwd)));
        }

        public  BaseUserModel(string username,Label note)
        {
            soen341dB_context = new soen341dBEntities();
            soen341dB_context.Configuration.ValidateOnSaveEnabled = false;
            newUser = new Users();
            UserIn = username;
            Notification = note;
        }
        public virtual void AddUserInDatabase()
        {

            soen341dB_context.Users.Add(newUser);

        }
        public virtual void SaveTheDatabase()
        {

                soen341dB_context.SaveChanges();
           
        }
        public virtual void WriteMessageLabel(string s)
        {

            Notification.Visible = true;
            Notification.Text = s;
        }
        public string EncryptUrl(string QueryStringTransmit)
        {
            byte[] encbuff = System.Text.Encoding.UTF8.GetBytes(QueryStringTransmit);
            return Convert.ToBase64String(encbuff);

        }

        public string DecryptUrl(string QueryStringRecieved)
        {
            byte[] decbuff = Convert.FromBase64String(QueryStringRecieved);
            return System.Text.Encoding.UTF8.GetString(decbuff);

        }


    }
}